package cn.emailChat.ai.service.util;

import org.springframework.stereotype.Component;

/**
 * @Description 线程开启和关闭
 * @Author susu
 * @Date 2025/8/20
 */
@Component
public class ThreadHeuristics {
    public String newThreadId(String contactEmail, String subjectNorm, String rootMessageId) {
        String seed = (contactEmail + "|" + subjectNorm + "|" + safe(rootMessageId));
        return "thread_" + Integer.toHexString(seed.hashCode());
    }
    public boolean shouldClose(String updatedSummary, String lastUser, String lastAssistant) {
        String s = (lastUser + " " + lastAssistant).toLowerCase();
        return s.contains("已解决") || s.contains("close the ticket")
                || s.contains("no further") || s.contains("resolved");
    }
    private String safe(String s) { return s == null ? "" : s; }
}
